/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package three2learn.Controller;

import java.io.IOException;
import java.util.LinkedList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.hibernate.Session;
import org.hibernate.Transaction;
import three2learn.Model.Student;
import three2learn.service.HibernateUtil;

/**
 *
 * @author Robbert
 */
public class StudentVerwijderController extends HttpServlet {
    /* HTTP GET request */

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        if (request.getParameter("id") != null) {
            
            long id = Long.parseLong(request.getParameter("id"));
            
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction transaction = session.beginTransaction();
            Object student = session.load(Student.class, id);
            session.delete(student);
            transaction.commit();
            
            response.sendRedirect("../index"); //Stuurt door naar de Gebruikers index
        }
    }
}